package com.shf.lease.web.admin.controller.apartment;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.shf.lease.entity.LabelInfo;
import com.shf.lease.enums.ItemType;
import com.shf.lease.result.Result;
import com.shf.lease.web.admin.controller.apartment.request.LabelTypeDelCmd;
import com.shf.lease.web.admin.service.LabelInfoService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 叶枫
 * @date 2024/7/4.
 */
@Tag(name = "标签管理")
@RestController
@RequestMapping("/admin/label")
public class LabelInfoController {

    @Resource
    private LabelInfoService labelInfoService;
    @Operation(summary = "查询标签列表")
    @GetMapping("/list")
    public Result<List<LabelInfo>> getLabelList(@RequestParam(required = false) ItemType type) {
        //构造查询条件
        LambdaQueryWrapper<LabelInfo> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq( type != null,LabelInfo::getType, type);
        return Result.ok(labelInfoService.list(queryWrapper));
    }
    @Operation(summary = "新增or更新标签")
    @RequestMapping(value = "/saveOrUpdate",method = {RequestMethod.POST,RequestMethod.PUT})
    public Result<?> saveOrUpdateLabel(@RequestBody LabelInfo labelInfo) {
        labelInfoService.saveOrUpdate(labelInfo);
        return Result.ok();
    }
    @Operation(summary = "删除标签")
   @DeleteMapping("/deleteById")
    public Result<?> deleteLabel(@RequestBody @Valid LabelTypeDelCmd request) {
        labelInfoService.removeById(request.getId());
        return Result.ok();
    }
}
